﻿@model IEnumerable<CarsManagement.Models.infos>

@{
    ViewBag.Title = "车辆列表";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<script src="~/Scripts/jquery-3.4.1.min.js"></script>
<script>
    $().ready(function () {
        $(".del").click(function () {
            var id = $(this).attr("alt");
            if (confirm("确认是否要删除" + id)) {
                //alert("是要删除"+id);
                $.ajax({
                    url: '@Url.Action("Del", "Carsinfos")',
                    data: { "id": id },
                    type: "post",//提交方式
                    dataType: "json",//后台返回格式
                    success: function (data) {
                        if (data.state == 0) {
                            alert("删除成功");
                            location.reload();
                        } else {
                            alert(data.msg);
                        }
                    },
                    error: function () {
                        alert("网络有问题，或者提交地址不存在");
                    },
                });
            }
        });
        ///全选框
        $("#one").click(function () {
            $(":input:checkbox:gt(0)").prop("checked", $(this).prop("checked"))
        });
        $("#DeleteBatch").click(function () {
            var car = new Array();//创建一个数组
            $("input:checkbox:gt(0):checked").each(function () {
                var id = $(this).val();
                car += id + ',';
            });
            if (car == 0) {
                alert("请选择你要删除的数据！！！");
            } else {
                var msg = "确定要删除吗？"
                if (confirm(msg) == true) {

                    //异步访问批量删除方法， 把数组传入controller层
                    $.ajax({
                        type: "post",
                        url: "/Carsinfos/DeleteBatch/",
                        data: { car: car },
                        success: function (data) {
                            if (data.state == 1000) {
                                alert("批量删除成功!");
                                location.reload();
                            }
                            else {
                                alert("批量删除失败!");
                            }
                        }

                    });
                }
            }
        });

    });
</script>
<h2>车辆列表</h2>
@using (Html.BeginForm())
{
    <label>车辆所在区</label>
    <input id="Text1" type="text" name="Address" />
    <input type="submit" value="搜索" />
    <input id="btn" type="button" value="添加" class="btn-info" onclick="location.href='/Carsinfos/Create/'" />
}
@using (Html.BeginForm())
{
    <table class="table">
        <tr>
            <th>
                <input type="checkbox" id="one" />
                <input id="DeleteBatch" value="批量删除" type="button" />
                @*<input type="submit" value="多选删除" onclick="return confirm('确定要删除吗?')" />*@
            </th>
            <th>
                @Html.DisplayNameFor(model => model.typee.CarType)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Name)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Phonenum)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Number)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.licence)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Addresss)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.States)
            </th>
            <th></th>
        </tr>

        @foreach (var item in Model)
        {
            <tr>
                <td>
                    <input type="checkbox" value="@item.Id" />
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.typee.CarType)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Name)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Phonenum)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Number)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.licence)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Addresss)
                </td>
                <td>
                    @if (item.States == "在库")
                    {
                        <input id=" btn" type="button" value="@item.States" class="btn-success" />
                    }
                    else
                    {
                        <input id=" btn1" type="button" value="@item.States" class="btn-default" />
                    }
                </td>
                <td>
                    <input type="button" value="编辑" class="btn-danger" onclick="location.href='/Carsinfos/Edit/'+@item.Id" />
                    @{
                        if (item.States == "在库")
                        {
                            <input id="btn" type="button" value="下架" onclick="location.href='/Carsinfos/Edits/'+@item.Id" />
                        }
                        else
                        {
                            <input id="btn" type="button" value="上架" class="btn-info" onclick="location.href='/Carsinfos/Edits/'+@item.Id" />
                        }

                    }
                    <input type="button" value="删除" class="del btn-default btn-danger" alt="@item.Id" />



                </td>

            </tr>

        }

    </table>

}

